package com.wzt.lianfirecontrol.http;

import android.content.Context;

import java.util.HashMap;

import okhttp3.FormBody;
import okhttp3.RequestBody;

public class Url {
    public static String HTTP = "http://";
    //   public static String URL_CONTENT = "36.97.144.52";   // 正式环境
    //  public static String POST = "80";    // 正式

        public static String URL_CONTENT = "220.178.27.116"; // 测试
        public static String POST = "1080";   // 测试

    // 阿里云接口
//    public static String URL_CONTENT = "121.196.13.132";
//    public static String POST = "8081";

//    public static String URL_CONTENT = "192.168.20.70";  // 本地测试
//    public static String POST = "80";   // 本地测试

    //    public static String URL_CONTENT = "121.41.193.53";
//    public static String POST = "";
    //public static String URL_CONTENT = "192.168.22.20";
    //   public static String URL_CONTENT = "192.168.20.90";
//    public static String URL_CONTENT = "36.97.144.50";
//    public static String POST = "http://220.178.27.116:1080";
    public static final String DEVICE = "/app";
    public static String REQUEST_HOST = HTTP + URL_CONTENT + ":" + POST;

    public static final String NVRPLAY = REQUEST_HOST + DEVICE + "/equ/getEasyNVRPlay";
    //当 等于 1时候调用
    public static final String EasyNVRTouch = REQUEST_HOST + DEVICE + "/equ/getEasyNVRTouchChannelStream";

    /**
     * 登录请求链接
     */
    public static String LOGIN_URL = REQUEST_HOST + "/auth/login";
    /**
     * 切换公司 查询全部公司
     */
    public static String QUERY_COMPANY_TREE = REQUEST_HOST + DEVICE + "/sundry/getSimpleCompanyTree";
    /**
     * 修改密码
     */
    public static String CHANGE_PASSWORD_URL = REQUEST_HOST + DEVICE + "/sundry/updatePassword";
    /**
     * 忘记密码
     */
    public static String FORGET_PASSWORD_URL = REQUEST_HOST + DEVICE + "/sundry/forgetPassword";
    /**
     * 更新用户信息
     */
    public static String UPDATE_USER_INFO_URL = REQUEST_HOST + DEVICE + "/sundry/update";
    /**
     * 首页请求链接
     */
    public static String HOME_URL = REQUEST_HOST + DEVICE + "/home/getEquSysInfoListByEquInfo";
    /**
     * 首页图片
     */
    public static String HOME_IMAGE_URL = REQUEST_HOST + DEVICE + "/sundry/getAppBackUpImg";
    /**
     * 首页统计
     */
    public static String HOME_COUNT_URL = REQUEST_HOST + DEVICE + "/home/getAppHomeCount";

    /**
     * 查询系统下的大楼和设备统计
     */
    public static String SYS_BUILD_LIST_URL = REQUEST_HOST + DEVICE + "/home/getMonitorSysBuildinglist";
    /**
     * 楼层
     */
    public static String DEVICE_FLOOR_URL = REQUEST_HOST + DEVICE + "/area/getFloorListByBuildingId";
    /**
     * 设备状态
     */
    public static String DEVICE_STATUS_URL = REQUEST_HOST + DEVICE + "/equ/getEquStatusBySysId";
    /**
     * 设备分类
     */
    public static String DEVICE_KIND_URL = REQUEST_HOST + DEVICE + "/equ/getEquTypeListBySysId";
    /**
     * 查询大楼内设备列表
     */
    public static String SYS_BUILD_DEVICE_LIST_URL = REQUEST_HOST + DEVICE + "/home/getEquMonitorInfoForCad";

    /**
     * 监控系统楼栋设备列表
     */
    public static String JIANKONG_BUILDING_URL = REQUEST_HOST + DEVICE + "/equ/getBuildingFloorVideoList";

    /**
     * 消息数量
     */
    public static String MESSAGE_COUNT_URL = REQUEST_HOST + DEVICE + "/msg/getMsgTypeCount";
    /**
     * 消息列表
     */
    public static String MESSAGE_LIST_URL = REQUEST_HOST + DEVICE + "/msg/getMsgListPage";
    /**
     * 消息详情
     */
    public static String MESSAGE_DETAIL_URL = REQUEST_HOST + DEVICE + "/msg/getMsgDetail";
    /**
     * 消息删除
     */
    public static String MESSAGE_DELETE_URL = REQUEST_HOST + DEVICE + "/msg/delMsgDetail";
    /**
     * 火警预警监管预警趋势
     */
    public static String CHART_TEND_URL = REQUEST_HOST + DEVICE + "/statisticalAnalysis/getAppStatisticalAnalysisDetail";
    /**
     * 我的团队
     */
    public static String MY_TEAM_URL = REQUEST_HOST + DEVICE + "/sundry/getMyTeamList";
    /**
     * 点击统计进入对应列表
     */
    public static String HOME_ALARM_URL = REQUEST_HOST + DEVICE + "/home/getHomeAlarmList";
    /**
     * 设备详情
     */
    public static String DEVICE_DETAIL_URL = REQUEST_HOST + DEVICE + "/equ/getEquDetail";
    /**
     * 设备监测情况
     */
    public static String DEVICE_JIANCE_URL = REQUEST_HOST + DEVICE + "/monitorHistory/getEquAttributeAll24HourByEquId";
    /**
     * 历史数据和详情页异常列表 设备运行状态 1报警 2故障 4监管 98预警 6 屏蔽
     */
    public static String DEVICE_HISTORY_URL = REQUEST_HOST + DEVICE + "/monitorHistory/getMonitorHistoryAlarmListPage";
    /**
     * 屏蔽历史数据
     */
    public static String DEVICE_PINGBI_HISTORY_URL = REQUEST_HOST + DEVICE + "/monitorHistory/getEquShieldInfoPageList";

    /**
     * 查询全部楼栋楼层设备
     */
    public static String FIND_ALL_DEVICE_URL = REQUEST_HOST + DEVICE + "/equ/getBuildingFloorEquList";
    /**
     * 报警复核单
     */
    public static String BJ_FUHE_LIST_URL = REQUEST_HOST + DEVICE + "/alarm/getAlarmInfoCheckPageList";
    /**
     * 报警复核真警
     */
    public static String BJ_FUHE_TRUE = REQUEST_HOST + DEVICE + "/alarm/checkTrue";
    /**
     * 报警复核误报
     */
    public static String BJ_FUHE_FALSE = REQUEST_HOST + DEVICE + "/alarm/checkFalse";
    /**
     * 报警复核监管确认已处理
     */
    public static String BJ_CHECK_OVER_URL = REQUEST_HOST + DEVICE + "/alarm/handlerSupervise";
    /**
     * 隐患整改信息流
     */
    public static String YIHUAN_LIST_URL = REQUEST_HOST + DEVICE + "/risk/getRiskInfoPageList";
    /**
     * 添加隐患整改
     */
    public static String YIHUAN_SAVE_URL = REQUEST_HOST + DEVICE + "/risk/addRisk";
    /**
     * 隐患整改记录信息流
     */
    public static String YIHUAN_RECORD_LIST_URL = REQUEST_HOST + DEVICE + "/risk/getRiskRecordList";
    /**
     * 添加隐患整改记录
     */
    public static String ADD_YIHUAN_RECORD_URL = REQUEST_HOST + DEVICE + "/risk/addRecord";
    /**
     * 消控室值班列表 格式：20200601or2020-06-01
     */
    public static String XKS_LIST_URL = REQUEST_HOST + DEVICE + "/duty/getRoomAndDailyRecordList";
    /**
     * 消控室值班详情
     */
    public static String XKS_RECORD_DETAIL_URL = REQUEST_HOST + DEVICE + "/duty/getDutyItemConfigById";
    /**
     * 消控室值班人员
     */
    public static String XKS_RERSON_URL = REQUEST_HOST + DEVICE + "/duty/getDutyManList";
    /**
     * 消控室值班事项列表
     */
    public static String XKS_RECORD_ITEM_URL = REQUEST_HOST + DEVICE + "/duty/getDutyItemList";
    /**
     * 消控室值班检查
     */
    public static String XKS_CHECK_URL = REQUEST_HOST + DEVICE + "/duty/addRecord";
    /**
     * 消控室提交异常
     */
    public static String XKS_YICHANG_SAVE_URL = REQUEST_HOST + DEVICE + "/duty/addProblem";
    /**
     * 消控室交接
     */
    public static String XKS_DETAIL_UPDATE_URL = REQUEST_HOST + DEVICE + "/duty/complete";
    /**
     * 紧急维修单信息流
     */
    public static String JINGJI_LIST_URL = REQUEST_HOST + DEVICE + "/repair/getRepairUrgentPageList";
    /**
     * 添加紧急维修单
     */
    public static String JINGJI_SAVE_URL = REQUEST_HOST + DEVICE + "/repair/addUrgentRepair";
    /**
     * 预约保单信息流
     */
    public static String YUYUE_LIST_URL = REQUEST_HOST + DEVICE + "/repair/getRepairTaskPageList";
    /**
     * 添加预约保单
     */
    public static String YUYUE_SAVE_URL = REQUEST_HOST + DEVICE + "/repair/addTask";
    /**
     * 预约保单维修记录
     */
    public static String YUYUE_RECORD_LIST_URL = REQUEST_HOST + DEVICE + "/repair/getRepairRecordListByTaskId";
    /**
     * 添加预约保单维修记录
     */
    public static String ADD_YUYUE_RECORD_URL = REQUEST_HOST + DEVICE + "/repair/addRecord";
    /**
     * 根据公司ID查询已关联的维保单位列表
     */
    public static String FIND_WEIBAO_COMPANY_URL = REQUEST_HOST + DEVICE + "/repair/getRepairCompanyList";
    /**
     * 根据维保公司ID查询维保人列表
     */
    public static String FIND_WEIBAO_PERSON_URL = REQUEST_HOST + DEVICE + "/repair/getRepairUserListByRepairCompanyId";
    /**
     * 指派维保人员
     */
    public static String POST_WEIBAO_PERSON = REQUEST_HOST + DEVICE + "/repair/assign";
    /**
     * 维保订单评价
     */
    public static String YUYUE_COMMIT_RAISE = REQUEST_HOST + DEVICE + "/repair/appraise";
    /**
     * 根据维保任务ID查询评价记录
     */
    public static String YUYUE_RAISE_LISR_URL = REQUEST_HOST + DEVICE + "/repair/getRepairAppraiseByTaskId";
    /**
     * 根据维保任务确认
     */
    public static String YUYUE_CHECK_URL = REQUEST_HOST + DEVICE + "/repair/complete";

    /**
     * 巡检巡查主界面 type:1：防火巡查 type:2：防火检查
     */
    public static String XUNCHA_LIST_URL = REQUEST_HOST + DEVICE + "/check/getCheckDailyPlanPageList";
    /**
     * 巡检巡查单个计划
     */
    public static String XUNCHA_PLAN_STATUS_URL = REQUEST_HOST + DEVICE + "/check/getBuildingCheckRecordList";
    /**
     * 巡检巡查问题列表
     */
    public static String XUNCHA_QUESTION_LIST_URL = REQUEST_HOST + DEVICE + "/check/getCheckProblemList";
    /**
     * 巡检巡查添加问题列表
     */
    public static String XUNCHA_ADD_QUESTION_URL = REQUEST_HOST + DEVICE + "/check/addProblem";
    /**
     * 巡检巡查巡查项
     */
    public static String XUNCHA_XUNCHA_ITEM_URL = REQUEST_HOST + DEVICE + "/check/getCheckOptionListByPlanId";
    /**
     * 防火巡查全部完成
     */
    public static String XUNCHA_COMPLETE_ALL_URL = REQUEST_HOST + DEVICE + "/check/completeCheck";
    /**
     * 防火巡检查开始检查
     */
    public static String XUNCHA_START_URL = REQUEST_HOST + DEVICE + "/check/startCheck";
    /**
     * 设备巡检楼层
     */
    public static String XUNCHA_DEVICE_BUILDING_URL = REQUEST_HOST + DEVICE + "/checkEqu/getCheckPlanEquPageList";
    /**
     * 设备巡检查询楼层下设备
     */
    public static String XUNCHA_DEVICE_FIND_URL = REQUEST_HOST + DEVICE + "/checkEqu/getCheckRecordByPlanIdAndFloorId";
    /**
     * 巡检巡查设备问题列表
     */
    public static String XUNCHA_DEVICE_QUESTION_LIST_URL = REQUEST_HOST + DEVICE + "/checkEqu/getCheckProblemEquList";
    /**
     * 设备巡检设备问题保存
     */
    public static String XUNCHA_DEVICE_QUS_SAVE_URL = REQUEST_HOST + DEVICE + "/checkEqu/addProblemEqu";
    /**
     * 设备巡检设备检查完成
     */
    public static String XUNCHA_DEVICE_COMPLETE_URL = REQUEST_HOST + DEVICE + "/checkEqu/completeCheckEqu";
    /**
     * 通过nfcid查询设备
     */
    public static String XUNCHA_DEVICE_FIND_BY_NFC_URL = REQUEST_HOST + DEVICE + "/checkEqu/getCheckRecordEquInfoByRfid";
    /**
     * 设备监控列表查询
     */
    public static String DEVICE_VIDEO_LIST_URL = REQUEST_HOST + DEVICE + "/equ/getEquVideoByIds";


    /**
     * app更新
     */
    public static String APP_UPDATE_URL = REQUEST_HOST + DEVICE + "/sundry/getAppVersion";
    /**
     * 上传文件
     */
    public static String UP_IMG_URL = REQUEST_HOST + "/minio/upload";
    /**
     * 删除文件
     */
    public static String DELETE_IMG_URL = REQUEST_HOST + "/minio/delete";


    /**
     * 获得Get的请求Url
     *
     * @param context
     * @param url
     * @param params  params 请求参数
     * @return
     */
    public static String getGetUrl(Context context, String url, HashMap<String, String> params) {
        StringBuilder sb = new StringBuilder(url);
        if (url.contains("?")) {
            sb.append("&");
        } else {
            sb.append("?");
        }
        params = getRequestParams(context, params);

        for (String key : params.keySet()) {
            sb.append(key);
            sb.append("=");
            sb.append(params.get(key));
            sb.append("&");
        }
        return sb.substring(0, sb.length() - 1);
    }

    public static HashMap<String, String> getRequestParams(Context context,
                                                           HashMap<String, String> params) {
        if (null == params) {
            params = new HashMap<>();
        }
//        params.put("f", "android");
//        // 版本code
//        params.put("code", Utils.getVersionCode(context) + "");
//        // 版本
//        params.put("v", Utils.getVersionName(context));
        return params;
    }


    public static String getPostParamsStr(HashMap<String, String> params) {
        StringBuilder sb = new StringBuilder();
        for (String key : params.keySet()) {
            sb.append(key);
            sb.append("=");
            sb.append(params.get(key));
            sb.append("&");
        }
        return sb.substring(0, sb.length() - 1);
    }

    public static RequestBody getPostRequestBody(HashMap<String, String> params) {
        FormBody.Builder builder = new FormBody.Builder();
        for (String key : params.keySet()) {
            builder.add(key, params.get(key));
        }
        return builder.build();
    }
}
